package org.xczy.consumer.order.consumerorder.controller;

import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import org.xczy.service.model.common.Result;
import org.xczy.service.model.entitys.pojo.Payment;
import javax.annotation.Resource;

@Log4j2
@RequestMapping("/consumer")
@RestController
public class OrderController {

  // private static final String PAYMENT_YRL = "http://localhost:8001"; 支付接口不能写死，让其自己去注册中心找（对应微服务名称）
  private static final String PAYMENT_YRL = "http://SPRING-CLOUD-PROVIDER-PAYMENT"; // SPRING-CLOUD-PROVIDER-PAYMENT

  @Resource
  private RestTemplate restTemplate;

  @GetMapping("/payment")
  public Result create(@RequestBody Payment payment){
    return restTemplate.postForObject( OrderController.PAYMENT_YRL + "/payment", payment, Result.class);
  }

  @GetMapping("/payment/{id}")
  public Result getPayment(@PathVariable("id") Long id){
    return restTemplate.getForObject(OrderController.PAYMENT_YRL + "/payment/" + id, Result.class);
  }


}
